<?php

// use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\Teacher\StudentController;
use App\Http\Controllers\Api\Teacher\PaperController;
use App\Http\Controllers\Api\Teacher\KnowledgeController;
use App\Http\Controllers\Api\Teacher\QuestionBankController;
use App\Http\Controllers\Api\Teacher\WpsController;
use App\Http\Controllers\Api\Teacher\CourseController;
use App\Http\Controllers\Api\Teacher\VirtualScoreController;
use \App\Http\Controllers\Api\Student\StudentController as StudentWebController;
use App\Http\Controllers\Api\Teacher\AdminController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });

// 公开路由
Route::post('teacher/login', [AuthController::class, 'teacherLogin']); // 教师登录
Route::post('student/login', [AuthController::class, 'studentLogin']); // 学生登录

// 教师端接口（仅教师可访问）
Route::middleware('auth.teacher')->group(function () {
    Route::post('teacher/logout', [AuthController::class, 'logout']); // 教师退出
    Route::get('teacher/students', [StudentController::class, 'index']); // 列表+搜索
    Route::post('teacher/students', [StudentController::class, 'store']); // 新增
    Route::put('teacher/students', [StudentController::class, 'update']); // 编辑（含id）
    Route::get('teacher/students/available-courses', [StudentController::class, 'getAvailableCourses']); // 可选课程
    Route::get('teacher/students/{id}/courses', [StudentController::class, 'getBoundCourses']); // 学生绑定的课程
    Route::post('teacher/students/bind-course', [StudentController::class, 'bindCourse']); // 绑定课程
    Route::delete('teacher/students/unbind-course', [StudentController::class, 'unbindCourse']); // 取消绑定
    // 试卷管理
    Route::get('teacher/papers', [PaperController::class, 'index']); // 试卷列表
    Route::post('teacher/papers', [PaperController::class, 'save']); // 新增试卷
    Route::put('teacher/papers', [PaperController::class, 'save']); // 编辑试卷
    Route::get('teacher/papers-questions', [PaperController::class, 'questionList']); // 题库列表
    // 理论知识管理
    Route::get('teacher/knowledges', [KnowledgeController::class, 'index']); // 知识列表
    Route::post('teacher/knowledges', [KnowledgeController::class, 'save']); // 新增知识
    Route::put('teacher/knowledges', [KnowledgeController::class, 'save']); // 编辑知识
    Route::get('teacher/knowledge-categories', [KnowledgeController::class, 'categoryList']); // 分类列表
    Route::post('teacher/knowledge-upload', [KnowledgeController::class, 'upload']); // 文件上传
    // 题库管理
    Route::get('teacher/questions', [QuestionBankController::class, 'index']); // 题库列表
    Route::post('teacher/questions', [QuestionBankController::class, 'save']); // 新增题目
    Route::put('teacher/questions', [QuestionBankController::class, 'save']); // 编辑题目
    Route::get('teacher/questions-categories', [QuestionBankController::class, 'categoryList']); // 分类列表

    // WPS文档管理
    Route::get('teacher/wpss', [WpsController::class, 'index']); // 文档列表
    Route::post('teacher/wpss', [WpsController::class, 'save']); // 新增文档
    Route::put('teacher/wpss', [WpsController::class, 'save']); // 编辑文档
    Route::post('teacher/wps-upload', [WpsController::class, 'upload']); // PDF上传
    // Route::get('teacher/wps-download', [WpsController::class, 'download']); // PDF下载
    // Route::get('teacher/wpss-categories', [WpsController::class, 'categoryList']); // 分类列表

    // 课程管理
    Route::get('teacher/courses', [CourseController::class, 'index']); // 课程列表
    Route::post('teacher/courses', [CourseController::class, 'save']); // 新增课程
    Route::put('teacher/courses', [CourseController::class, 'save']); // 编辑课程
    Route::get('teacher/course-detail', [CourseController::class, 'detail']); // 课程详情
    Route::get('teacher/course-categories', [CourseController::class, 'categoryList']); // 分类列表

    // 虚拟教室成绩管理
    Route::get('teacher/virtual-scores', [VirtualScoreController::class, 'index']); // 成绩列表
    
    // 辅助接口（绑定资源用）
    Route::get('teacher/available-knowledges', [CourseController::class, 'availableKnowledges']); // 可选知识
    Route::get('teacher/available-papers', [CourseController::class, 'availablePapers']); // 可选试卷

    Route::get('teacher/accounts', [AdminController::class, 'index']);        // 获取账号列表
    Route::post('teacher/accounts', [AdminController::class, 'save']);     // 新增账号
    Route::get('teacher/account-details', [AdminController::class, 'show']);    // 获取账号详情
    Route::put('teacher/accounts', [AdminController::class, 'save']); // 更新账号信息
    Route::delete('teacher/accounts', [AdminController::class, 'destroy']); // 删除账号
    Route::post('teacher/avatar', [AdminController::class, 'uploadAvatar']); // 上传头像
});

// 学生端接口（仅学生可访问）
Route::middleware('auth.student')->group(function () {
    Route::post('student/logout', [AuthController::class, 'logout']); // 学生退出
    // 首页内容
    Route::get('student/home', [StudentWebController::class, 'home']);
    // 课程列表
    Route::get('student/courses', [StudentWebController::class, 'courseList']);
    // 课程详情
    Route::get('student/course-detail', [StudentWebController::class, 'courseDetail']);
    // 试卷详情
    Route::get('student/paper-detail', [StudentWebController::class, 'paperDetail']);
    // 提交试卷
    Route::post('student/submit-paper', [StudentWebController::class, 'submitPaper']);
    // 获取试卷结果
    Route::get('student/paper-result', [StudentWebController::class, 'paperResult']);
    // 虚拟教室成绩列表
    Route::get('student/virtual-classroom-scores', [StudentWebController::class, 'virtualClassroomScores']);
    // 修改个人信息
    Route::put('student/profile', [StudentWebController::class, 'updateProfile']);
    // 标记知识已学习
    Route::post('student/mark-knowledge', [StudentWebController::class, 'markKnowledge']);
});

// 管理员账号管理路由
Route::middleware('auth.teacher')->group(function () {
    Route::prefix('admin')->group(function () {
       
    });
});
